package com.kienbk1910.productmanager;

import com.kienbk1910.common.Commom;
import com.kienbk1910.productmanager.provider.DBHelper;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

public class ProductAdapter extends CursorAdapter{
	 private LayoutInflater mInflater;
	public ProductAdapter(Context context, Cursor c) {
		super(context, c);
		// TODO Auto-generated constructor stub
		 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public void bindView(View arg0, Context arg1, Cursor arg2) {
		// TODO Auto-generated method stub
		TextView name = (TextView) arg0.findViewById(R.id.name);
		TextView number =(TextView) arg0.findViewById(R.id.number);
		TextView manu =(TextView) arg0.findViewById(R.id.manufuctrue);
		TextView cost =(TextView) arg0.findViewById(R.id.cost);
		int positon = arg2.getPosition();
	
		name.setText(arg2.getString(arg2.getColumnIndex(DBHelper.NAME)));
		number.setText(String.valueOf(arg2.getPosition()+1));
		manu.setText(arg2.getString(arg2.getColumnIndex(DBHelper.MANUFACTURER)));
		cost.setText(Commom.intToStringWithplot(arg2.getInt(arg2.getColumnIndex(DBHelper.COST))));
	}

	@Override
	public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		return mInflater.inflate(R.layout.item_product, arg2, false);
	}

}
